/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.toools.gwt.wmc.client.disposer.gui;

import java.util.Collection;
import java.util.Vector;
import org.toools.gwt.widget.client.bc.BusinessObjectPanel;
import org.toools.gwt.widget.client.bc.StringAttribute;
import org.toools.gwt.wmc.jpa.Container;
import org.toools.gwt.wmc.jpa.Disposer;

/**
 *
 * @author Manuel
 */
public class DisposerPanel extends BusinessObjectPanel {

    StringAttribute name = null;

    Collection<Container> childs = new Vector<Container>();

    public DisposerPanel(Object bp) {
        super(bp, 2);

        name = new StringAttribute("name", false);
        name.setMaxLength(50);

        this.add( name );

        recreateContent();
        preselect();
        validate();

        setStatus("* missing or invalid input");
    }

    public void preselect() {
        if (getBusinessObject() != null) {
            Disposer a = (Disposer) getBusinessObject();
            name.setAttributeValue(a.getName());
        } else {
            name.setAttributeValue("");
        }
    }

    public void addChild(Container c) {
        this.childs.add(c);
    }

    public void map() {
        if (getBusinessObject() == null) {
            setBusinessObject(new Disposer());
        }
        Disposer d = (Disposer) getBusinessObject();
        d.setName("" + name.getAttributeValue());
        if (childs.size() > 0)
            d.setContainers(childs);
    }

}
